{extend name="layout" /}
{block name="body"}
<div class="row">
    <div class="col-lg-12">
        <form>
            <div class="card">
                <div class="card-body">
                    <div class="form-group">
                        <label for="title">帖子标题</label>
                        {if $show == 1}
                            <input type="hidden" class="form-control" id="id" value="{$article.id}" disabled>
                        {/if}
                        <input type="text" class="form-control" id="title" {if $show == 1} value="{$article.title}" {/if} placeholder="请输入帖子标题">
                    </div>
                    <div class="form-group">
                        <label for="content">帖子内容</label>
                        <textarea class="form-control" aria-label="With textarea" id="content" placeholder="帖子内容" style="height: 200px;">{if $show == 1}{$article.content}{/if}</textarea>
                    </div>
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input type="text" class="form-control" id="username" placeholder="用户名"  {if $show == 1} value="{$article.username}" disabled {/if}  placeholder="" >
                    </div>
                    {if $show == 1}
                    <div class="form-group">
                        <label for="platename">板块名称</label>
                        <input type="text" class="form-control" id="platename" {if $show == 1}  value="{$article.platename}" disabled {/if} placeholder="请输入板块名称" >
                    </div>
                    {else:}
                    <div class="form-group">
                        <label for="plateid">板块名称</label>
                        <select class="form-control" id="plateid">
                            <option value="" disabled>请选择板块</option>
                            {foreach :query('plate') as $key=>$value }
                            <option value="{$value['id']}">{$value["platename"]}(appid:{$value['appid']})</option>
                            {/foreach}
                        </select>
                    </div>
                    {/if}
                    {if $show == 1}
                    <div class="form-group">
                        <label for="appname">app名称</label>
                        <input type="text" class="form-control" id="appname" {if $show == 1} value="{$article.appname}" {/if} disabled>
                    </div>
                    {else:}
                    <div class="form-group">
                        <label for="appid">app</label>
                        <select class="form-control" id="appid">
                            <option value="" disabled>请选择app</option>
                            {foreach :query('app') as $key=>$value }
                            <option value="{$value['appid']}">{$value["appname"]}(appid:{$value['appid']})</option>
                            {/foreach}
                        </select>
                    </div>
                    {/if}
                    {if $show == 1}
                    <div class="form-group">
                        <label for="ip">ip</label>
                        <input type="text" class="form-control" id="ip"  value="{$article.ip}" disabled  >
                    </div>
                    {/if}
                    <div class="form-group file-group">
                        <label for="video_url">视频链接</label>
                        <div class="input-group">
                            <input type="text" id="video_url" class="form-control file-value" name="video_url" {if $show == 1} value="{$article.video_url}" {/if}
                                placeholder="视频链接">
                            <input type="file" accaccept=".mp4" style="display: none">
                            <div class="input-group-btn">
                                <button class="btn btn-default file-browser" type="button">上传视频</button>
                            </div>
                        </div>
                    </div>
                    <div class="form-group file-group">
                        <label for="video_cover">视频封面</label>
                        <div class="input-group">
                            <input type="text" id="video_cover" class="form-control file-value" name="video_cover" {if $show == 1} value="{$article.video_cover}" {/if}
                                placeholder="视频封面">
                            <input type="file" accaccept=".jpg,.png,.gif,.jpeg" style="display: none">
                            <div class="input-group-btn">
                                <button class="btn btn-default file-browser" type="button">上传视频封面</button>
                            </div>
                        </div>
                    </div>
                        <div class="form-group">
                            <label for="pic_url">图片链接</label>
                            <textarea class="form-control" aria-label="With textarea" placeholder="图片链接" id="pic_url" style="height: 200px;">{if $show == 1}{$article.pic_url}{/if}</textarea>
                        </div>
                        <div class="form-group">
                            <label for="network_pictures">网络图片链接</label>
                            <textarea class="form-control" aria-label="With textarea" placeholder="网络图片链接" id="network_pictures" style="height: 200px;">{if $show == 1}{$article.network_pictures}{/if}</textarea>
                        </div>
                    <div class="form-group">
                        <label for="status">状态</label>
                        <select class="form-control" id="status" >
                            <option value="0" {if $show == 1} {if $article["status"] == 0}selected{/if}{/if}>待审核</option>
                            <option value="1" {if $show == 1} {if $article["status"] == 1}selected{/if}{/if}>正常</option>
                            <option value="2" {if $show == 1} {if $article["status"] == 2}selected{/if}{/if}>审核未通过</option>
                            <option value="3" {if $show == 1} {if $article["status"] == 3}selected{/if}{/if}>文章锁定</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="top">是否置顶</label>
                        <select class="form-control" id="top">
                            <option value="0" {if $show == 1}  {if $article["top"] == 0}selected{/if} {/if}>不置顶</option>
                            <option value="1" {if $show == 1}  {if $article["top"] == 1}selected{/if} {/if}>置顶</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="popular">是否热门</label>
                        <select class="form-control" id="popular">
                            <option value="0" {if $show == 1}  {if $article["popular"] == 0}selected{/if} {/if}>不置顶</option>
                            <option value="1" {if $show == 1}  {if $article["popular"] == 1}selected{/if} {/if}>置顶</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="is_type">文章类型</label>
                        <select class="form-control" id="is_type">
                            <option value="0" {if $show == 1}  {if $article["is_type"] == 0}selected{/if} {/if}>图文帖子</option>
                            <option value="1" {if $show == 1}  {if $article["is_type"] == 1}selected{/if} {/if}>视频帖子</option>
                        </select>
                    </div>
                    <button type="button" {if $show == 1} onclick="updatepost()" {else:} onclick="addpost()" {/if} class="btn btn-w-sm btn-primary mb-2">提交</button>
                    <button type="button" class="btn btn-default mb-2"
                        onclick="javascript:history.back(-1);return false;">返
                        回
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}
{block name="js"}
{if $show == 1}
<script>
    function updatepost() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        var id = $.trim($("#id").val());
        var title = $.trim($("#title").val());
        var content = $.trim($("#content").val());
        var status = $.trim($("#status").val());
        var video_url = $.trim($("#video_url").val());
        var video_cover = $.trim($("#video_cover").val());
        var pic_url = $.trim($("#pic_url").val());
        var network_pictures = $.trim($("#network_pictures").val());
        var top = $.trim($("#top").val());
        var popular = $.trim($("#popular").val());
        var is_type = $.trim($("#is_type").val());
        $.ajax({
            type: "POST",
            url: "{:url('bbs/editpost')}",
            data: {
                id: id,
                title: title,
                content: content,
                status: status,
                video_url: video_url,
                video_cover: video_cover,
                pic_url:pic_url,
                network_pictures:network_pictures,
                top:top,
                popular:popular,
                is_type:is_type,
            },
            dataType: "json",
            success: function (data) {
                l.destroy();
                if (data.code == 1) {
                    notify.success(data.msg);
                    $("#exampleModal").modal('hide');
                    $('#tb_departments').bootstrapTable('refresh');
                } else {
                    notify.error(data.msg);
                    $("#exampleModal").modal('hide');
                }
            },
            error: function () {
                l.destroy();
                notify.error("系统错误");
            }
        })
    }
</script>
{else:}
<script>
    function addpost() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        var title = $.trim($("#title").val());
        var content = $.trim($("#content").val());
        var username = $.trim($("#username").val());
        var plateid = $.trim($("#plateid").val());
        var appid = $.trim($("#appid").val());
        var status = $.trim($("#status").val());
        var video_url = $.trim($("#video_url").val());
        var video_cover = $.trim($("#video_cover").val());
        var pic_url = $.trim($("#pic_url").val());
        var top = $.trim($("#top").val());
        var popular = $.trim($("#popular").val());
        var is_type = $.trim($("#is_type").val());
        $.ajax({
            type: "POST",
            url: "{:url('bbs/addpost')}",
            data: {
                title: title,
                content: content,
                username: username,
                plateid: plateid,
                appid: appid,
                status:status,
                video_url:video_url,
                video_cover:video_cover,
                pic_url:pic_url,
                top:top,
                popular:popular,
                is_type:is_type,
            },
            dataType: "json",
            success: function (data) {
                l.destroy();
                if (data.code == 1) {
                    notify.success(data.msg,function () {
                        history.back(-1);
                    },1000);
                } else {
                    notify.error(data.msg);
                }
            },
            error: function () {
                l.destroy();
                notify.error("系统错误");
            }
        })
    }
</script>
{/if}
{/block}